<!-- 监控详情 -->

<template>
  <EasyModal v-model="model" v-bind="MAP.MODEL_PROPS">
    <DeviceAlarm :id="one.alarmId" :content="one.alarmContent" @change="toChange" />

    <MajorTitle :title="one.deviceName">
      <template #right>
        <ParamDate :param="infoParam" bind="startTime" history small noClear @change="changeDate" />
      </template>
    </MajorTitle>

    <WebForm class="marginBottom relative">
      <MyTable />

      <MyChart />
    </WebForm>
  </EasyModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import store from './store'
import props from './props'
import mixDetail from '@admin/components/detail/mixDetail'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'DetailMonitor',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixStore(store), mixDetail],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 属性注册 (抽取以便查阅)
   */
  props,

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听单项就绪
     */
    readyOne(ready) {
      if (ready) {
        const { infoParam, one, MAP } = this
        const first = one.yxzt || one.gzzt || one.sbqt || one.propList.find((item) => item)
        if (!first) return

        infoParam.deviceId = one.id
        infoParam.code = first.code
        MAP.tipInfo = `查询${first.name}统计图`
        this.startInfo()
      }
    },

    /**
     * 监听提交失败
     */
    needSubmit(need) {
      !need && !this.readySubmit && this.startOne()
    },
  },

  /**
   * 创建完成 (先抽取再调用)
   */
  created() {
    const { type, $root: { iot_type_selectDict: typeDict }, MAP } = this
    if (type) MAP.WORD = CORE.dict(typeDict, type)
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 切换日期
     */
    changeDate(startTime) {
      this.infoParam.endTime = CORE.timeNum(startTime, -1, 1)
      this.startInfo()
    },
  },
}
</script>
